#include "httplib.h"
using namespace httplib;

int main()
{
    Server ser;
    ser.Get("/hello", [&](const Request& req, Response& resp)
    {
        resp.status = 200;
        resp.set_content("hello world!", "text/plain");
    });

    ser.Get(R"(/number/(\d+))", [&](const Request& req, Response& resp)
    {
        resp.status = 200;
        auto number = req.matches[1]; // 0下标中保存的是整体path，往后的下标保存的是捕捉的数据
        resp.set_content(number, "text/plain");
    });

    ser.Post("/upload", [&](const Request& req, Response& resp)
    {
       if(req.has_file("file1") == false)
       {
            std::cout << "no this file can upload" << std::endl;
            resp.status = 404;
            return;
       }

       const auto& file = req.get_file_value("file1");
       std::cout << file.filename << std::endl;
       std::cout << file.name << std::endl;
       std::cout << file.content << std::endl;
       std::cout << file.content_type << std::endl;
    });
    ser.listen("0.0.0.0", 8888);
    return 0;
}
